package com.zmytest.service.impl;

import com.zmytest.dto.PermissionDto;
import com.zmytest.dto.ResponseDto;
import com.zmytest.model.Permission;
import com.zmytest.repository.PermissionRepository;
import com.zmytest.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
 * Created on 2018/12/20.
 *
 * @author zhangmingyu
 */
@Service
@Slf4j
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionRepository permissionRepository;

    @Override
    public ResponseDto<Permission> create(PermissionDto permissionDto) {
        if (!ObjectUtils.isEmpty(permissionDto.getId())) {
            return ResponseDto.fail("user id must be null");
        }
        Permission result = permissionRepository.save(new Permission(permissionDto.getName()));
        return ResponseDto.success(result);
    }

}
